package com.cg.service.impl;

import com.cg.dao.OrganizeMapper;
import com.cg.dto.OrgPageDto;
import com.cg.entity.Organize;
import com.cg.service.OrganizeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Organize)表服务实现类
 *
 * @author chengong
 * @since 2023-12-18 18:10:30
 */
@Service("organizeService")
public class OrganizeServiceImpl implements OrganizeService {
    @Resource
    private OrganizeMapper organizeMapper;



    /**
     * 验证Code是否存在
     */
    @Override
    public Integer queryCountByOrgCode(String orgName) {
        return organizeMapper.queryCountByOrgCode(orgName);
    }

    /**
     * 新增组织编码
     */
    @Override
    public Integer createOrganize(Organize organize) {
        Integer count = 0;
        try {
            count = organizeMapper.createOrganize(organize);
        }catch (Exception e){
            e.printStackTrace();
        }

        return count;
    }

    /**
     * 查询组织全部信息-分页并按照名称模糊查询
     */
    @Override
    public PageInfo<Organize> organizeList(OrgPageDto orgPageDto) {
        PageHelper.startPage(orgPageDto.getPageNum(),orgPageDto.getPageSize());
        List<Organize> organizes = organizeMapper.organizeList(orgPageDto.getOrgName());
        PageInfo<Organize> pageInfo = new PageInfo<>(organizes);
        return pageInfo;
    }

    /**
     * 修改组织信息
     */
    @Override
    public Integer setOrganize(Organize organize) {
        Integer count = 0;
        try {
            count = organizeMapper.setOrganize(organize);
        }catch (Exception e){
            e.printStackTrace();
        }
        return count;
    }

    /**
     * 删除组织信息
     */
    @Override
    public Integer removeOrganize(Integer id) {
        return organizeMapper.removeOrganize(id);
    }

    /**
     * 查询组织详情
     */
    @Override
    public Organize queryOrganizeByOrganizeId(Integer organizeId) {
        return organizeMapper.queryOrganizeByOrganizeId(organizeId);
    }


}
